import request from '@/utils/request';

export async function getPickingTaskByPage(params: any) {
  return request('/api/product/getPickingTaskByPage', {
    method: 'POST',
    data: params,
  });
}

export async function addPickingTask(params: any) {
  return request('/api/product/addPickingTask', {
    method: 'POST',
    data: params,
  });
}

export async function updatePickingTask(params: any) {
  return request('/api/product/updatePickingTask', {
    method: 'POST',
    data: params,
  });
}

//编辑物料updatePickingDetails
export async function updatePickingDetails(params: any) {
  return request('/api/product/updatePickingDetails', {
    method: 'POST',
    data: params,
  });
}

export async function delPickingTask(params: any) {
  return request('/api/product/delPickingTask', {
    method: 'POST',
    data: params,
  });
}

export async function exportPickingTask(params: any) {
  return request('/api/product/exportPickingTask', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

//导出细节
export async function exportPickingDetails(params: any) {
  return request('/api/product/exportPickingDetails', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

//分料完成/api/product/pickingFinish
export async function pickingFinish(params: any) {
  return request('/api/product/pickingFinish', {
    method: 'POST',
    params: {
      id: params,
    },
  });
}

//模糊匹配/api/product/getPickingDetailsByPageLike
export async function getPickingDetailsByPageLike(data: any, params: any) {
  return request('/api/product/getPickingDetailsByPageLike', {
    method: 'POST',
    data: params,
    params: {
      like: data.like,
      pickingTaskCode: data.pickingTaskCode,
    },
  });
}
//模糊匹配/api/product/getPickingDetailsByPageLike
export async function getPickingDetailsByPageLike2(data: any, params: any) {
  return request('/api/product/getPickingDetailsByPageLike2', {
    method: 'POST',
    data: params,
    params: {
      like: data.like,
      pickingTaskCode: data.pickingTaskCode,
    },
  });
}

//新版模糊匹配/api/product/getPickingTaskBySomething
export async function getPickingTaskBySomething(data: any) {
  // console.log(data.s, 's');
  // console.log(data.pickingTasks, 'data.pickingTasks');
  return request('/api/product/getPickingTaskBySomethings', {
    method: 'POST',
    params: {
      // pickingTasks: JSON.stringify(data.pickingTasks),
      s: data.s,
    },
    data: data.pickingTasks,
  });
}

///api/project/getBatchPlanByPage
export async function getBatchPlanByPage(params: any) {
  return request('/api/project/getBatchPlanByPage', {
    method: 'POST',
    data: params,
  });
}

//分料接口，修改数量
export async function allocation(data: any) {
  return request('/api/product/allocation', {
    method: 'POST',
    params: {
      id: data.id,
      pickingNum: data.thistimeQty,
    },
  });
}

// 分料接口2，按工单的，修改本次数量后进行分料
export async function allocation2(data:any) {
  return request('/api/product/allocation2',{
    method: 'POST',
    params: {
      pickingdetails_id: data.id,
      notissueqty: data.notIssuedQty,
      outboundQty: data.outboundQty,
    }
  })
}

// 分料接口3，按批次的，修改本次数量后进行分料
export async function allocation3(data:any) {
  return request('/api/product/allocation3',{
    method: 'POST',
    params: {
      batchPlanId: data.batchPlanId,
      materialCode: data.materialCode,
      notissueqty: data.notIssuedQty,
      outboundQty: data.outboundQty,
    }
  })
}

//扫描序列号
export async function scanSerNo(data: any) {
  return request('/api/product/scanSerNo', {
    method: 'POST',
    params: {
      id: data.id,
      SerNo: data.serialNum,
    },
  });
}

//分料接口,扫描序列号
export async function getBatchBarcodesByPickingTaskCode(data: any) {
  return request('/api/product/getBatchBarcodesByPickingTaskCode', {
    method: 'GET',
    responseType: 'blob',
    params: {
      materialCode: data.materialCode,
      materialSpec: data.materialSpec,
    },
  });
}

//批量打印物料
export async function getMaterialPdfs(data: any) {
  return request('/api/pack/getMaterialPdfs', {
    method: 'GET',
    responseType: 'blob',
    params: {
      ids: data,
    },
  });
}

export default {
  getPickingTaskByPage,
  addPickingTask,
  updatePickingTask,
  delPickingTask,
  exportPickingTask,
};
